#include "head.h"

void OPEN_ERR(int fd)
{
    if (fd == -1)
    {
        perror("Error");
    }
}

int main(int argc, char const *argv[])
{
    int fd_1 = open(argv[1], O_RDWR | O_CREAT | O_APPEND, 0666);
    if (3 > argc)
    {
        printf("格式错误 : %s file_dest file_src\n", argv[0]);
        return 0;
    }

    for (int i = 2; i <= argc; i++)
    {
        if (argv[i] != NULL)
        {
            int fd = open(argv[i], O_RDWR | O_CREAT, 0666); // 以读写模式打开 并且 清空写
            char buffer[1024];
            size_t bytes;
            while ((bytes = read(fd , buffer, sizeof(buffer))) > 0)
            {
                write(fd_1, buffer, bytes);
            }
            close(fd);
        }
    }
    close(fd_1);
}